package com.bigger.controller;

import com.bigger.dto.BusinessPageDTO;
import com.bigger.dto.UpdateBusinessDTO;
import com.bigger.entity.Business;
import com.bigger.result.PageResult;
import com.bigger.result.Result;
import com.bigger.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;

    @GetMapping("/get")
    public Result<PageResult<Business>> page(BusinessPageDTO businessPageDTO){
        PageResult<Business> pageResult=businessService.page(businessPageDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/add")
    public Result<String> addBusiness(@RequestBody UpdateBusinessDTO updateBusinessDTO){
        businessService.addBusiness(updateBusinessDTO);
        return Result.success("添加成功");
    }

    @PutMapping("/update")
    public Result<String> update(@RequestBody UpdateBusinessDTO updateBusinessDTO){
        businessService.update(updateBusinessDTO);
        return Result.success("修改成功");
    }

    @DeleteMapping("/delete")
    public Result<String> delete(@RequestParam Long id){
        businessService.delete(id);
        return Result.success("删除成功");
    }

    @GetMapping("/get/{id}")
    public Result<Business> getById(@PathVariable("id") Long id){
        Business business = businessService.getById(id);
        return Result.success(business);
    }
}
